//
//  XDHomeCellHeaderView.m
//  XDEducation
//
//  Created by apple on 2017/4/8.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDHomeCellHeaderView.h"

@interface XDHomeCellHeaderView ()

/** icon */
@property(nonatomic,strong) UIImageView *iconImageView;

/** title */
@property(nonatomic,strong) UILabel *titleLabel;



/** more bg view */
@property(nonatomic,strong) UIView *moreView;

/** more label */
@property(nonatomic,strong) UILabel *moreLabel;

/** right arrow */
@property(nonatomic,strong) UIImageView *arrowImageView;

@end

@implementation XDHomeCellHeaderView


-(instancetype)initWithTitle:(NSString *)title MoreBtnStatus:(BOOL)status{

    if (self = [super init]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        _iconImageView = [[UIImageView alloc]init];
        _iconImageView.image = [UIImage imageNamed:@"home_icon_blue_default"];
        [self addSubview:_iconImageView];
        
        [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.centerY.equalTo(self.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = title;
        _titleLabel.textColor = UIColorFromRGB(0x4c4c4c);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_iconImageView.mas_right).offset(15);
            make.centerY.equalTo(_iconImageView.mas_centerY);
        }];
        
        
        if (status) {
            
            _moreView = [[UIView alloc]init];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(moreClicked)];
            [_moreView addGestureRecognizer:tap];
            
            [self addSubview:_moreView];
            
            [_moreView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.mas_right).offset(-15);
                make.centerY.equalTo(self.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(50, 30));
            }];
            
            _moreLabel = [[UILabel alloc]init];
            _moreLabel.text = @"更多";
            _moreLabel.textColor = UIColorFromRGB(0x808080);
            _moreLabel.font = [UIFont systemFontOfSize:14];
            [_moreView addSubview:_moreLabel];
            
            [_moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_moreView.mas_left);
                make.centerY.equalTo(_moreView.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(30, 20));
            }];
            
            _arrowImageView = [[UIImageView alloc]init];
            _arrowImageView.image = [UIImage imageNamed:@"home_icon_next_default"];
            [_moreView addSubview:_arrowImageView];
            
            [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_moreView.mas_right);
                make.centerY.equalTo(_moreView.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(6, 10));
            }];

        }
        
    }
    return self;
}


-(void)moreClicked{

    if(self.moreBlock){
        
        self.moreBlock();
    }
}


@end
